<template>
  <div class="admin-layout">
    <NavBar />
    <div class="admin-container">
      <div class="admin-sidebar">
        <h3 class="sidebar-title">管理员控制中心</h3>
        <ul class="sidebar-menu">
          <li>
            <router-link to="/admin/dashboard" active-class="active">
              <i class="el-icon-dashboard"></i>
              <span>数据总览</span>
            </router-link>
          </li>
          <li>
            <router-link to="/admin/teachers" active-class="active">
              <i class="el-icon-user"></i>
              <span>教师管理</span>
            </router-link>
          </li>
          <li>
            <router-link to="/admin/students" active-class="active">
              <i class="el-icon-user-solid"></i>
              <span>学生管理</span>
            </router-link>
          </li>
          <li>
            <router-link to="/admin/classes" active-class="active">
              <i class="el-icon-office-building"></i>
              <span>班级管理</span>
            </router-link>
          </li>
          <li>
            <router-link to="/admin/statistics" active-class="active">
              <i class="el-icon-data-analysis"></i>
              <span>数据分析</span>
            </router-link>
          </li>
          <li>
            <router-link to="/admin/profile" active-class="active">
              <i class="el-icon-setting"></i>
              <span>个人设置</span>
            </router-link>
          </li>
        </ul>
      </div>
      <div class="admin-content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script setup>
import NavBar from '@/components/NavBar.vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';

const router = useRouter();

onMounted(() => {
  // 检查用户是否为管理员
  const userRole = localStorage.getItem('userRole');
  if (userRole !== '3') {
    // 如果不是管理员，重定向到合适的页面
    if (userRole === '1') {
      router.push('/design/new'); // 教师首页
    } else if (userRole === '2') {
      router.push('/student/dashboard'); // 学生首页
    } else {
      router.push('/'); // 默认首页
    }
  }
});
</script>

<style scoped>
.admin-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f7fa;
}

.admin-container {
  display: flex;
  flex: 1;
  margin-top: 60px; /* 导航栏高度 */
}

.admin-sidebar {
  width: 240px;
  background-color: #ffffff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 20px 0;
  height: calc(100vh - 60px);
  position: fixed;
  top: 60px;
  left: 0;
  overflow-y: auto;
  z-index: 10; /* 提高层级 */
}

.sidebar-title {
  font-size: 18px;
  color: #1a73e8;
  padding: 0 20px;
  margin-bottom: 20px;
  border-left: 4px solid #1a73e8;
}

.sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-menu li {
  margin-bottom: 5px;
}

.sidebar-menu li a {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  color: #606266;
  text-decoration: none;
  transition: all 0.3s;
}

.sidebar-menu li a i {
  margin-right: 10px;
  font-size: 18px;
}

.sidebar-menu li a:hover {
  color: #1a73e8;
  background-color: #f0f7ff;
}

.sidebar-menu li a.active {
  color: #1a73e8;
  background-color: #f0f7ff;
  border-right: 4px solid #1a73e8;
  font-weight: 600;
}

.admin-content {
  flex: 1;
  padding: 20px;
  margin-left: 240px; /* 侧边栏宽度 */
  min-height: calc(100vh - 100px);
  overflow-x: hidden;
  position: relative;
  z-index: 1;
  width: calc(100% - 240px); /* 设置宽度确保不会超出 */
}

@media (max-width: 768px) {
  .admin-sidebar {
    width: 200px;
  }
  
  .admin-content {
    margin-left: 200px;
  }
}
</style> 